<?php
/*
 * estudo de padrões de projetos com php
 * author: fabricio s costa
 * version: 1.0
 * site: http://fabriciojf.com
 */
class PDOConnectionFactory {

    public $con = null;
    public $dbType = "mysql";

    public $host = "localhost";
    public $user = "root";
    public $senha = "rootroot";
    public $db = "jumbo";

    public $persistent = false;

    public function PDOConnectionFactory( $persistent=false ){
        if( $persistent != false){ $this->persistent = true; }
    }

    public function getConnection(){
        try{
            $this->con = new PDO($this->dbType.":host=".$this->host.";dbname=".$this->db, $this->user, $this->senha,
                array( PDO::ATTR_PERSISTENT => $this->persistent ) );
            return $this->con;
        }catch ( PDOException $ex ){ echo "Erro: ".$ex->getMessage(); }
    }

    // desconecta
    public function Close(){
        if( $this->con != null )
        $this->con = null;
    }
}
?>
